package com.letcode.study.juc;

/**
 * @Date 2022/11/13 23:29:45
 * @Author luopeng
 */
public class StringInternDemo {
    public static void main(String[] args) {
//        String x = "alibaba";
        String a = new StringBuilder().append("ali").append("baba").toString();
        // 当调用intern方法时,如果池已经包含一个等于{@link String(Object)}方法确定的{@code String}对象的字符串,则返回池中的字符串否则,这个{ @code String}
        //     * 对象添加到池中,并返回对此{@code String}对象的引用。
        String b = a.intern();
        System.out.println(a);
        System.out.println(b);
        System.out.println(a == b);

        String c = new StringBuilder().append("ja").append("va").toString();
//        String c = "java";
        String d = c.intern();
        System.out.println(c);
        System.out.println(d);
        System.out.println(c == d);

    }
}
